package game.Sokoban;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;

public class GLRenderer implements Renderer{

	private Context	context;
	private Game game;
	
	public GLRenderer(Context context,Game game) {
		this.context = context;
		this.game = game;
	}

	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		game.init(gl,context);
	}

	public void onDrawFrame(GL10 gl) {
		gl.glEnable(GL10.GL_BLEND);
		gl.glEnable(GL10.GL_TEXTURE_2D);			//Enable Texture Mapping ( NEW )
		gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
		gl.glClearColor(0.1f, 0.80f, 0.3f, 1);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); // clear Screen and Depth Buffer
		gl.glLoadIdentity();					// Reset the Modelview Matrix
		// Drawing
		gl.glTranslatef(-10f, -6f, -15.0f);		// move camera 5 units INTO the screen
		game.draw(gl);						
	}

	public void onSurfaceChanged(GL10 gl, int width, int height) {
		if(height != 0) {
		gl.glViewport(0, 0, width, height); 	//Reset The Current Viewport
		gl.glMatrixMode(GL10.GL_PROJECTION); 	//Select The Projection Matrix
		gl.glLoadIdentity(); 					//Reset The Projection Matrix
		GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f); //Calculate The Aspect Ratio Of The Window
		gl.glMatrixMode(GL10.GL_MODELVIEW); 	//Select The Modelview Matrix
		gl.glLoadIdentity(); 					//Reset The Modelview Matrix
		}
	}


}
